using System;
using System.Collections.Generic;
using System.Diagnostics.Eventing.Reader;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SmartLink.EnumLibrary;
using SmartLink.Repository;

namespace SmartLink.DBLogger
{
    public class LogToDBHelper
    {
        private LOG_OperateRepo _repo;
        private static LogToDBHelper helper;

        public LogToDBHelper()
        {
            _repo = new LOG_OperateRepo();
        }

        public static LogToDBHelper GetInstance()
        {
            return helper ?? (helper = new LogToDBHelper());
        }

        /// <summary>
        /// 参数日志（异步）
        /// </summary>
        public void LogInfo(string operationModule, string content, int userId)
        {
            var t = new Task(() =>
            {
                var logInfo = new LOG_Operate()
                {
                    LogLevel = LogLevelEnum.操作日志.GetHashCode(),
                    LogContent = content,
                    OperationModule = operationModule,
                    Creator = userId,
                    CreateTime = DateTime.Now
                };

                _repo.Add(logInfo);
            });
            t.Start();
        }

        /// <summary>
        /// 错误日志（异步）
        /// </summary>
        public void LogError(string operationModule, string content, int userId)
        {
            var t = new Task(() =>
            {
                var logInfo = new LOG_Operate()
                {
                    LogLevel = LogLevelEnum.错误日志.GetHashCode(),
                    LogContent = content,
                    OperationModule = operationModule,
                    Creator = userId,
                    CreateTime = DateTime.Now
                };

                _repo.Add(logInfo);
            });
            t.Start();
        }
    }
}
